package com.ydj.app.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ydj.app.entity.WebUser;
import com.ydj.app.protocol.http.web.*;
import com.ydj.app.service.ChatService;
import com.ydj.framework.exception.CommonException;
import com.ydj.framework.protocol.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@Slf4j
@RestController
@RequestMapping("/web/chat")
@Api(tags = "WEB-对话")
public class WebChatController {

    @Autowired
    private ChatService chatService;

    @ResponseBody
    @ApiOperation(value = "获取对话历史记录")
    @ApiOperationSupport(order = 10)
    @PostMapping(value = "/historyList")
    public JsonResult<WebChatHistoryListRes> historyList(@RequestBody @Validated WebChatHistoryListReq req, @ApiIgnore WebUser webUser) throws CommonException {
        WebChatHistoryListRes res = chatService.webHistoryList(req, webUser);
        return JsonResult.success(res);
    }

    @ResponseBody
    @ApiOperation(value = "清除对话历史记录")
    @ApiOperationSupport(order = 20)
    @PostMapping(value = "/clearHistory")
    public JsonResult<?> clearHistory(@RequestBody @Validated WebChatClearHistoryReq req, @ApiIgnore WebUser webUser) throws CommonException {
        chatService.webClearHistory(req, webUser);
        return JsonResult.success();
    }

    @ResponseBody
    @ApiOperation(value = "获取一个对话的内容")
    @ApiOperationSupport(order = 30)
    @PostMapping(value = "/chatDetail")
    public JsonResult<WebChatChatDetailRes> chatDetail(@RequestBody @Validated WebChatChatDetailReq req, @ApiIgnore WebUser webUser) throws CommonException {
        WebChatChatDetailRes res = chatService.webChatDetail(req, webUser);
        return JsonResult.success(res);
    }
}